from typing import List


# index方法找不到会抛出异常，所以建议使用enumerate
class Solution:
    def __init__(self):
        pass

    # 暴力求解
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        nums_len = len(nums) - 1
        for i in range(nums_len):
            n = i + 1
            while n <= nums_len:  # n可以选择最后一个哦
                if nums[i] + nums[n] == target:
                    return [i, n]
                else:
                    n += 1

    def twoSum02(self, nums: List[int], target: int) -> List[int]:
        nums_len = len(nums) - 1
        for i in range(nums_len):
            temp = target - nums[i]
            try:
                return [i, nums[i:].index(temp)]
            except Exception as e:
                pass

    def twoSum03(self, nums: List[int], target: int) -> List[int]:
        nums_len = len(nums) -1
        for i in range(nums_len):
            temp = target - nums[i]
            for x, value in enumerate(nums):
                if value == temp and x != i:
                    return [i,x]


if __name__ == "__main__":
    nums = [2, 7, 11, 15]
    target = 9
    solution = Solution()
    print(solution.twoSum03(nums, target))
